/**
 * Created with IntelliJ IDEA.
 * Description: leetcode.简单题.移除元素
 */

class Solution {
    public static int removeElement(int[] nums, int val) {
        int i = 0;
        int length = nums.length;
        while(i < length) {
            while(nums[i] == val && i < length) {
                nums[i] = nums[length - 1];
                length--;
            }
            i++;
        }
        return length;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{4,5};
        int length = 0;
        length = removeElement(nums,5);
        for (int i = 0; i < length; i++) {
            System.out.print(nums[i] + " ");
        }
    }
}

public class Test {
}
